// Copyright 2019 JDAI Inc.
// License ()
// Author:  XXXXXXX (), XXXX@jd.com
// Filename:  Http2Client.h
// Description:
// Created:  11/14/19 15:23:43
// Version:  1.0
// Company:  JDAI
//
//
#ifndef Http2Client_H_
#define Http2Client_H_

#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <curl/curl.h>
#include <sys/time.h>

#include <string>

using std::string;

class HttpListener {
  public:
    virtual void onRecvData(void* usrCtx, const void* data, int dataLen) = 0;
    virtual void onRecvData(void* usrCtx, string& data) = 0;
    virtual void onError(int errno) = 0;

  private:

};

class Http2Client {
  public:
    Http2Client(HttpListener* listener);
    virtual ~ Http2Client();
    void setSrvURL(const string& url);
    int addHead(const string headList[], int len);
    void freeHead();
    int post(const string& data);

  public:
    HttpListener* mpListener;
    void* mpUsrCtx;

  private:
    CURL* mpCurl;
    struct curl_slist* mpHeadList;
    string mHead;
    string mSrvURL;
    static bool gmIsGlobalInit;

};

#endif
